import sys
import os
from pathlib import Path
from PyQt5.QtWidgets import QApplication
from PyQt5.QtCore import QSettings
from PyQt5.QtGui import QIcon
from PyQt5.QtQml import QQmlApplicationEngine,qmlRegisterType
# from PyQt5.QtQuickControls2 import QQuickStyle
import qml_rc
import platform
import logging
from logging.handlers import RotatingFileHandler
import getpath
sys.stdout = open(sys.stdout.fileno(), mode='w', encoding='utf8', buffering=1)
sys.stderr = open(sys.stderr.fileno(), mode='w', encoding='utf8', buffering=1)
handlers = [RotatingFileHandler(filename="report.log", maxBytes=10 * 1024 * 1024, encoding='utf-8', backupCount=3),
            logging.StreamHandler(sys.stdout)]
logging.basicConfig(level=logging.DEBUG,
                    format='%(asctime)s - %(name)s - %(levelname)s -%(funcName)s - %(message)s',
                    handlers=handlers)
logging.info('begin')


def main():
    # if platform.uname().system=="Windows":
    #     pass
    # else:
    #     from Watcher import Watcher
    #     Watcher()
    QApplication.setApplicationName("report")
    # QApplication.setOrganizationName("QtProject")

    app = QApplication(sys.argv)
    # print(dir(app))
    engine = QQmlApplicationEngine()
    TaoQuickImportPath=r"D:\home\TaoQuick\src"
    engine.addImportPath(TaoQuickImportPath);
    qml_file =os.path.join(getpath.getpath(),'main.qml')  # 'mainw.qml'
    engine.load(qml_file)

    if not engine.rootObjects():
        sys.exit(-1)
    r = app.exec()
    sys.exit(r)


if __name__ == '__main__':
    main()
